#!/usr/bin/env python
# -*- coding: utf-8 -*-
# title       :
# author      : lee

import sys
import os
import logging
from SceneCheckTool.checkScript.CheckBase import CheckBase

try:
    import maya.cmds as cmds
    # import pymel.core as pm
    import JTK.jmaya.core as jmc

except:
    pass

logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


class LayersClear(CheckBase):
    def __init__(self):
        super(LayersClear, self).__init__()
        pass

    def get_unuse_layers(self):
        display_layers = cmds.ls(type="displayLayer")
        render_layers = cmds.ls(type="renderLayer")

        unuse_layers = []
        for layer in display_layers:
            if "defaultLayer" not in layer:
                unuse_layers.append(layer)
        for layer in render_layers:
            if "defaultRenderLayer" not in layer:
                unuse_layers.append(layer)
        return unuse_layers

    def clear_layer(self):
        unuse_layers = self.get_unuse_layers()
        cmds.delete(unuse_layers)

    def check(self):
        result_proc = self.get_unuse_layers()
        if result_proc:
            result_log = u'Error:%s\n' % result_proc
        else:
            result_log = u'Succeed:没有问题\n'

        return result_log

    def fix(self):
        layers = self.get_unuse_layers()
        try:
            self.clear_layer()
            result_log = u'Succeed:%s层已清除\n' % layers
            return result_log
        except:
            return u'Error:%s没有删除成功\n' % layers




